-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move subcommands logic to Completer class #264
Conversation
Review status: 0 of 10 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. ycmd/completers/completer.py, line 197 [r1] (raw file): ycmd/completers/completer.py, line 202 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 10 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. ycmd/completers/completer.py, line 197 [r1] (raw file): I also think that But this will be for another PR. ycmd/completers/completer.py, line 202 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 10 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. ycmd/completers/completer.py, line 202 [r1] (raw file): For tern completer, I did something similar to cs completer: subcommands = {
'StartServer': ( lambda self, request_data, args:
self._StartServer() ),
'StopServer': ( lambda self, request_data, args:
self._StopServer() ),
'ConnectToServer': ( lambda self, request_data, args:
self._ConnectToServer( args ) ),
'GoToDefinition': ( lambda self, request_data, args:
self._GoToDefinition( request_data) ),
'GoTo': ( lambda self, request_data, args:
self._GoToDefinition( request_data) ),
'GetType': ( lambda self, request_data, args:
self._GetType( request_data) ),
'GetDoc': ( lambda self, request_data, args:
self._GetDoc( request_data) ),
} Called like this: def DefinedSubcommands( self ):
return self.subcommands.keys()
def OnUserCommand( self, arguments, request_data ):
if not arguments or arguments[ 0 ] not in TernCompleter.subcommands:
raise ValueError( self.UserCommandsHelpMessage() )
return TernCompleter.subcommands[ arguments[ 0 ] ]( self,
request_data,
arguments[ 1: ] ) Comments from the review on Reviewable.io |
Implement OnUserCommand and DefinedSubcommands methods in Completer class. Create a new abstract method GetSubcommandsMap. This method should return a map between the subcommands and the Completer methods to call.
Subcommands list from Definedsubcommands is now alphabetically sorted.
4e7843f
to
f45c847
Compare
Updates:
Review status: 0 of 7 files reviewed at latest revision, 2 unresolved discussions. ycmd/completers/completer.py, line 202 [r1] (raw file): Comments from the review on Reviewable.io |
Fix also a typo in the Clang completer. Comments from the review on Reviewable.io |
Reviewed 1 of 10 files at r1, 5 of 9 files at r2. ycmd/completers/completer.py, line 268 [r2] (raw file): Comments from the review on Reviewable.io |
Review status: 6 of 7 files reviewed at latest revision, 3 unresolved discussions. ycmd/completers/completer.py, line 268 [r2] (raw file): Fwiw I need to pass an arg for tern, so maybe I can make that change on top (as for now it is yagni) Comments from the review on Reviewable.io |
ycmd/completers/completer.py, line 268 [r2] (raw file): Comments from the review on Reviewable.io |
Review status: 6 of 7 files reviewed at latest revision, 3 unresolved discussions. ycmd/completers/completer.py, line 268 [r2] (raw file): Comments from the review on Reviewable.io |
ycmd/completers/completer.py, line 268 [r2] (raw file): Comments from the review on Reviewable.io |
Reviewed 1 of 9 files at r2. ycmd/completers/completer.py, line 197 [r1] (raw file):
I don't agree with this, it is not just a container but basically a Facade which merges candidates from different completer, so you use it as a completer but you're actually receiving results from more than one. Maybe it doesn't have the best name but it is a Completer for sure. Comments from the review on Reviewable.io |
ycmd/completers/completer.py, line 197 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: all files reviewed at latest revision, 2 unresolved discussions. ycmd/completers/completer.py, line 197 [r1] (raw file): Comments from the review on Reviewable.io |
This LGTM. Review status: all files reviewed at latest revision, 2 unresolved discussions. Comments from the review on Reviewable.io |
LGTM too. @homu r+ Review status: all files reviewed at latest revision, 1 unresolved discussion. Comments from the review on Reviewable.io |
📌 Commit f45c847 has been approved by |
Reviewed 1 of 10 files at r1, 6 of 9 files at r2. Comments from the review on Reviewable.io |
⚡ Test exempted - status |
Move subcommands logic to Completer class Currently, each semantic completer reimplements the `OnUserCommand` and `DefinedSubcommands` in about the same way. To avoid duplication of code, this PR moves the logic of these methods to the `Completer` class. Completers only need to implement a new function `GetSubcommandsMap` that return a map between the subcommands name and the methods to call. The map structure is explained in the method documentation. Minor improvements: - `DefinedSubcommands` now returns an alphabetically sorted list (tests updated to reflect this); - Fix issue in PR #263. Important: if this PR is merged, the `OmniCompleter` class will need to be updated in YCM by inheriting from `GeneralCompleter` instead of `Completer` or implementing the `GetSubcommandsMap` method. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/264) <!-- Reviewable:end -->
This is really good stuff. Thanks for making the change. Review status: all files reviewed at latest revision, 1 unresolved discussion. ycmd/completers/completer.py, line 197 [r1] (raw file): But @micbou has a good point in that there might be room for a SemanticCompleter class. Comments from the review on Reviewable.io |
Currently, each semantic completer reimplements the
OnUserCommand
andDefinedSubcommands
in about the same way. To avoid duplication of code, this PR moves the logic of these methods to theCompleter
class. Completers only need to implement a new functionGetSubcommandsMap
that return a map between the subcommands name and the methods to call. The map structure is explained in the method documentation.Minor improvements:
DefinedSubcommands
now returns an alphabetically sorted list (tests updated to reflect this);Important: if this PR is merged, the
OmniCompleter
class will need to be updated in YCM by inheriting fromGeneralCompleter
instead ofCompleter
or implementing theGetSubcommandsMap
method.